//
//  UILabel+TinyTextAlign.m
//  TinyRadioGroup
//
//  Created by kingdomrain on 2020/11/25.
//  Copyright © 2020 sunline. All rights reserved.
//

#import "UILabel+TinyTextAlign.h"

@implementation UILabel (TinyTextAlign)

// label顶部对齐
- (void)topAlignment
{
    CGSize size = [self.text sizeWithAttributes:@{NSFontAttributeName:self.font}];
    CGRect rect = [self.text boundingRectWithSize:CGSizeMake(self.frame.size.width, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:self.font} context:nil];
    self.numberOfLines = 0;
    NSInteger newLinesToPad = (self.frame.size.height - rect.size.height)/size.height;
    for (NSInteger i = 0; i < newLinesToPad; i ++) {
        self.text = [self.text stringByAppendingString:@"\n "];
    }
}

@end
